import 'package:aio/aio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:app/generated/app_strings.dart';
import 'package:app/src/http/bean/wroks/address_bean.dart';
import 'package:app/src/http/bean/wroks/contract_bean.dart';
import 'package:app/src/ui/route/works/public/items/ui_base.dart';
import 'package:app/src/ui/route/works/public/items/ui_card.dart';

///送货地址信息
class UiAddress {
  ///data 信息
  ///oldData 历史信息
  static Widget build(BuildContext context, Address? data, Address? oldData,
      {String? title}) {
    List<Widget> children = [];
    if (StringUtils.isEmpty(title)) {
      title = AppStrings.of(context).AddressInformation; //送货地址信息
    }
    children.add(UiBase.title(context, title)); //标题
    children.add(UiBase.item(context, AppStrings.of(context).FactoryName2,
        data?.FactoryName, oldData?.FactoryName,
        isNew: data?.isNew() ?? false)); //发货工厂
    children.add(UiBase.item(
        context,
        AppStrings.of(context).DeliveryAddressType,
        data?.DeliveryAddressType,
        oldData?.DeliveryAddressType)); //送货地址类型
    children.add(UiBase.item(context, AppStrings.of(context).DeliveryAddress,
        data?.DeliveryAddress, oldData?.DeliveryAddress)); //详细送货地址
    children.add(UiBase.item(context, AppStrings.of(context).Distance,
        data?.Distance, oldData?.Distance,
        unit: AppStrings.of(context).km)); //距离
    children.add(UiBase.item(context, AppStrings.of(context).RoutePreference,
        data?.RoutePreference, oldData?.RoutePreference)); //路线偏好
    children.add(
        UiBase.itemWithButon(context, AppStrings.of(context).CheckRoute, () {
      var startLatitude = data?.StartLatitude; //起点纬度
      var startLongitude = data?.StartLongitude; //起点经度
      var startName = data?.FactoryName; //起点位置
      var endLatitude = data?.EndLatitude; //目的地纬度
      var endLongitude = data?.EndLongitude; //目的地经度
      var endName = data?.DeliveryAddress; //目的地名称
      AioPlugin.goMap(context, endLatitude, endLongitude, endName,
          startLatitude: startLatitude,
          startLongitude: startLongitude,
          startName: startName,
          RoutePreference: data?.RoutePreference);
    })); //路线
    var column = UiBase.column(context, children);
    var card = UiCard.build(context, column);
    return card;
  }
}
